package st.business.tepth.business.user.busnumber.workholder.repair.finish;

import io.reactivex.disposables.Disposable;
import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.config.Url;
import st.shadow.library.core.net.callback.IError;
import st.shadow.library.core.net.callback.ISuccess;
import st.shadow.library.core.net.rx.RxRestClient;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-03-26 11:11
 */

public class RepairCompleteModel implements RepairCompleteContract.Model {

    @Override
    public Disposable complete(String token, int id,
                               String repairTaskIds,
                               String reason,
                               int status, final OnDataConvertListener<String> listener) {
        return RxRestClient.builder()
                .url(Url.RepairCompletionInspection)
                .params("id", id)
                .params("repairTaskIds", repairTaskIds)
                .params("reason", reason)
                .params("token", token)
                .params("state",status)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(response);
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .post();
    }
    @Override
    public Disposable cancelFinishWork(String token, int repairId, final OnDataConvertListener<String> listener) {
        return RxRestClient.builder()
                .url(Url.CancelFinishWork)
                .params("repairId", repairId)
                .params("token", token)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(response);
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .get();
    }
}
